package com.hcx.excel.xlsx;

import java.util.ArrayList;
import java.util.List;

public class Row {
	private List<Cell> cells;
	private int rowNum;
	private int columnCount;

	public Row(int rowNum, int columnCount) {
		this.rowNum = rowNum;
		this.columnCount = columnCount;
		cells = new ArrayList<Cell>(columnCount);
	}

	/**
	 * 从 0 开始
	 * @return
	 */
	public int getRowNum() {
		return rowNum;
	}

	public int getColumnCount() {
		return columnCount;
	}

	public void addCell(Cell cell, int index) {
		if (index == cells.size()) {
			cells.add(cell);
		} else if (index < cells.size()) {
			cells.remove(index);
			cells.add(index, cell);
		} else if (index > cells.size()) {
			while (cells.size() != index) {
				cells.add(null);
			}
			cells.add(cell);
		}
	}

	public Cell[] getCells() {
		return cells.toArray(new Cell[columnCount]);
	}
}
